package com.frxuexi.report.viewmodel

import com.frxuexi.lib_base.ApiResponse
import com.frxuexi.lib_base.BaseViewModel
import com.frxuexi.lib_base.RequestType
import com.frxuexi.lib_base.UiState
import com.frxuexi.report.intent.ReportIntent
import com.frxuexi.report.repository.ReportRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class ReportViewModel @Inject constructor(private val reportRepository: ReportRepository):
    BaseViewModel<ReportIntent,UiState<Any>>() {
    override fun handlerIntent(intent: ReportIntent) {
        when(intent){
            is ReportIntent.getReports->{
                httpRequest(reportRepository.getReports(intent.map) as Flow<ApiResponse<Any>>)
            }
            is ReportIntent.addReport->{
                httpRequest(reportRepository.addReport(intent.map) as Flow<ApiResponse<Any>>,
                    RequestType.COMMIT
                )
            }
            else->{}
        }
    }
}